package com.sr.servlet.book;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.service.BookService;


/**
 * Servlet implementation class BookDeleteServlet
 */
@WebServlet("/deleteBookServlet")
public class BookDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookDeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 删除也是通过bookName删除
		String id=request.getParameter("id");
		System.out.println(id);
		BookService bs=new BookService();
		boolean result=bs.deleteBookById(Integer.parseInt(id));
		if(result) {
			request.getRequestDispatcher("findBooklist").forward(request, response);//删除成功 要跳回查询所有的servlet 在进行查询  不是直接跳到jsp
			System.out.println("删除成功！");
		}else {
			response.sendRedirect("index.jsp");
			System.out.println("无法删除！");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
